const sequelize = require("../../utils/sequelize");
/**
 * 用户数量统计 -年月
 * @param req
 * @param res
 * @returns {Promise<{months: *[], values: *[]}>}
 */

exports.testService = async function (req, res) {
  try {
    const str =
      "SELECT" +
      " DATE_FORMAT( createdAt, '%Y-%m' ) AS 'month'," +
      " COUNT(*) AS 'value'" +
      " FROM" +
      " USERS" +
      " GROUP BY" +
      " MONTH" +
      " ORDER BY 'month' ASC;";
    const [result] = await sequelize.query(str);
    const data = {
      months: [],
      values: [],
    };
    result.forEach((item) => {
      data.months.push(item.month);
      data.values.push(item.value);
    });
    return data;
  } catch (error) {
    throw Error(error);
  }
};
